<template>
  <a-modal
    title="打印"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
     @cancel="handleCancel"
  >
  <template slot="footer">
        <a-button key="back" @click="handleCancel">
          取消
        </a-button>
        <a-button key="submit" type="primary"  @click="handleSubmit">
          打印
        </a-button>
  </template>
  <div class="print"  ref="print">
    <a-row>
      <a-col :span="24" class="title">
       <strong>{{ form.mainTitle }}</strong>
      </a-col>
    </a-row>
    <a-row>
      <a-col :span="24" class="title">
       <strong>{{ form.subheading }}</strong>
      </a-col>
    </a-row>
    <a-row v-if="form.billStatus === 1 || form.billStatus === 4">
      <a-col :span="12" class="ydxx">
       <span></span>
      </a-col>
      <a-col :span="12" class="ydxx">
       <span class="item-end">單據號：{{ form.no }}</span>
      </a-col>
    </a-row>
    <a-row>
      <a-col :span="8" class="ydxx">
       <span>住户：{{ form.zhuhu }}</span>
      </a-col>
      <a-col :span="8" class="ydxxf">
       <span >收租日：{{ form.rentedDay }}</span>
      </a-col>
      <a-col :span="8" class="ydxx">
       <span class="item-end">账单周期：{{ form.rentStartDate }}-{{ form.rentEndDate }}</span>
      </a-col>
    </a-row>
    <div class="main-content">
      <a-row class="main-content-item cb"  v-for="(item,index) in cbList" :key="index">
        <a-col :span="6" class="ydxxit cbit">
          {{ item.typeName }}
        </a-col>
        <a-col :span="6" class="ydxxit cbit">
          {{ item.amount }}(單價)/保底{{ item.solder }}
        </a-col>
        <a-col :span="6" class="ydxxit cbit">
          用量{{ item.dosage }} ({{ item.preReading }} - {{ item.reading }})
        </a-col>
        <a-col :span="6" class="ydxxit ">
          {{ item.cost }}元
        </a-col>
      </a-row>
       <a-row class="main-content-item cb"  >
        <a-col :span="6" class="ydxxit" v-for="(item,index) in feiList" :key="index">
          {{ item.rentAmountName }}：{{ item.amount }}元
        </a-col>
      </a-row>
      <a-row class="main-content-item">
        <a-col :span="24" class="dj">
          <h3>小計：{{ form.subtotal }}元 <span v-if="form.billStatus === 1 || form.billStatus === 4">實收金額：{{ form.receiveAmount }}元</span></h3>
        </a-col>
      </a-row>
    </div>
      <a-row>
      <a-col :span="8" class="ydxx">
       <span>打印日期：{{ form.dayinDate }}</span>
      </a-col>
      <a-col :span="8" class="ydxx">
       <span>付款人：</span>
      </a-col>
      <a-col :span="8" class="ydxx">
       <span class="item-end">收款人：{{ form.payee }}</span>
      </a-col>
    </a-row>
  </div>
  </a-modal>
</template>

<script>
  import { houseBillPrintMsgForBill } from '@/api/modular/main/housebill/houseBillManage'
  import moment from 'moment'
  export default {
    data () {
      return {
        visible: false,
        confirmLoading: false,
        form: {},
        feiList: [],
        cbList: []
      }
    },
    methods: {
      moment,
      // 初始化方法
      edit (record) {
        this.visible = true
        this.initXgData(record)
      },
      initXgData(id) {
         houseBillPrintMsgForBill(id).then((res) => {
              if (res.code === 200) {
                this.form = res.data
                this.feiList = this.form.feiList
                this.cbList = this.form.cbList
              } else {
                this.$message.error(res.msg)
              }
            }).finally((res) => {
         })
      },
      handleSubmit () {
        this.$print(this.$refs.print) // 使用
        this.handleCancel()
      },
      handleCancel () {
        this.visible = false
        this.form = {}
        this.feiList = []
        this.cbList = []
      }
    }
  }
</script>
<style scoped>
.print{
  padding: 6px 10px;
}
.title{
  text-align: center;
  tab-size: 20px;
}
.item-end{
  float: right;
}
.main-content{
  margin-top: 10px;
  margin-bottom: 10px;
  border: solid 1px rgb(218, 211, 211);
}
.dj{
 padding-left: 6px;
}
.main-content-item{
 padding: 6px 0px;
}
.zkxx{
  margin: 6px 0px 6px 6px;
}
.divider-content-only{
    font-size: 20px;
    margin-bottom: 10px;
  }
  .divider-content-center-only{
      margin-top: 10px;
  }
  .span-calculateStyle{
    font-size: 14px;
    margin-bottom: 20px;
  }
.phone{
  margin-left: 40px;
}
.ydxxf{
  text-align: center;
}
.cb{
    border-bottom: solid 1px rgb(218, 211, 211);
}
.cbit{
  border-right: solid 1px rgb(218, 211, 211);
}
.ydxxit{
  text-align: center;
}
</style>
